<?php
require 'sessionInfo.class.php' ;

if (!is_null($_POST["username"])) {
	$username = $_POST["username"];
}

if (!is_null($_POST["password"])) {
	$password = $_POST["password"];
} 

$db = "mymessageboard";
$root = "root";
$password = "root";
$host = "localhost";
$con = mysqli_connect($host, $root, $password);

if (!$con) {
	exit("服务器连接失败");
}

mysqli_select_db($con, $db);
//
$name = $_POST["username"];
$pwd = md5($_POST["password"]);
$key = "";

// $sql = "insert into Persons (name, password, ukkey) Values ('".$name."','".$pwd."','".$userKey."')";
$sql = "SELECT * FROM Persons
		WHERE name = '".$name."' AND password = '".$pwd."'";

$ret = mysqli_query($con, $sql);
if (!$ret) {
	echo "登录失败，请重新登录";
	exit();
} else {
	while($row = mysqli_fetch_array($ret)) {
			$key = $row["ukkey"];
		}
}

SessionInfo::setLoginInfo("username", $name);
SessionInfo::setLoginInfo("password", $pwd);
SessionInfo::setLoginInfo("ukkey", $key);


$url = "http://localhost:8888/phpdemo/messageboard/";
header('Location: index.php', true);
?>